package com.uroad.jilinpda.activity;

import android.os.Bundle;
import android.view.KeyEvent;
import android.view.View;
import android.widget.EditText;
import android.widget.TextView;

import com.uroad.jilinpda.R;
import com.uroad.jilinpda.common.BaseActivity;
import com.uroad.jilinpda.layer.LoginLayer;
import com.uroad.jilinpda.presenter.LoginPresenter;
import com.uroad.jilinpda.util.ClickUtil;

import butterknife.BindView;
import butterknife.ButterKnife;
import butterknife.OnClick;

public class LoginActivity extends BaseActivity {

    @BindView(R.id.tv_login)
    TextView tv_login;
    @BindView(R.id.tv_sendcode)
    TextView tv_sendcode;
    @BindView(R.id.tv_setting)
    TextView tv_setting;
    @BindView(R.id.et_phone)
    EditText et_phone;
    @BindView(R.id.etPassword)
    EditText etPassword;

    private LoginPresenter presenter;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setBaseContentLayoutWithoutTitle(R.layout.activity_login);
        ButterKnife.bind(this);
        initPresenter();
    }

    private void initPresenter(){
        presenter = new LoginPresenter(this);
        presenter.attachView(this);
        presenter.checkAttach();
    }

    public void setTvSendcode(String str){
        tv_sendcode.setText(str);
    }

    public void showToast(String str){
        showShortToast(str);
    }

    public void openMainActivty(){
        openActivity(MainActivity.class);
        finish();
    }
    public void tvSendcodeClickAble(boolean isAble){
        tv_sendcode.setClickable(isAble);
    }
    @OnClick({R.id.tv_login, R.id.tv_sendcode, R.id.tv_setting})
    public void onClick(View view) {
        switch (view.getId()){
            case  R.id.tv_sendcode:
                if (ClickUtil.isFastClick()) {//防止连续点击
                    presenter.sendCode(et_phone.getText().toString().trim());
                }
                break;
            case  R.id.tv_login:
                if (ClickUtil.isFastClick()) {//防止连续点击
                    presenter.login(et_phone.getText().toString().trim(), etPassword.getText().toString().trim());
                }
                break;
            case  R.id.tv_setting:
                if (ClickUtil.isFastClick()) {//防止连续点击
                    openActivity(SettingActivity.class);
                }
                break;
        }
    }

}
